home *** CD-ROM | disk | FTP | other *** search
/ Champak 52 / Volume 52 - JOGO DISK .iso / Games / shopdrop.swf / scripts / __Packages / smashing / Point.as < prev    next >
Text File  |  2007-09-27  |  4KB  |  193 lines

  1. class smashing.Point
  2. {
  3.    function Point(x, y)
  4.    {
  5.       this.x = Number(x);
  6.       this.y = Number(y);
  7.    }
  8.    function get length()
  9.    {
  10.       return Math.sqrt(this.x * this.x + this.y * this.y);
  11.    }
  12.    function set length(newLength)
  13.    {
  14.       if(this.__get__length() != 0)
  15.       {
  16.          var _loc2_ = newLength / this.__get__length();
  17.          this.x *= _loc2_;
  18.          this.y *= _loc2_;
  19.       }
  20.    }
  21.    function get lengthSqu()
  22.    {
  23.       return this.x * this.x + this.y * this.y;
  24.    }
  25.    function copy()
  26.    {
  27.       return new smashing.Point(this.x,this.y);
  28.    }
  29.    function addPoint(p)
  30.    {
  31.       return new smashing.Point(p.x + this.x,p.y + this.y);
  32.    }
  33.    function subtractPoint(p)
  34.    {
  35.       return new smashing.Point(this.x - p.x,this.y - p.y);
  36.    }
  37.    function addScalar(n)
  38.    {
  39.       return new smashing.Point(this.x + n,this.y + n);
  40.    }
  41.    function subtractScalar(n)
  42.    {
  43.       return new smashing.Point(this.x - n,this.y - n);
  44.    }
  45.    function addPointMe(p)
  46.    {
  47.       this.x += p.x;
  48.       this.y += p.y;
  49.    }
  50.    function subtractPointMe(p)
  51.    {
  52.       this.x -= p.x;
  53.       this.y -= p.y;
  54.    }
  55.    function addScalarMe(n)
  56.    {
  57.       this.x += n;
  58.       this.y += n;
  59.    }
  60.    function subtractScalarMe(n)
  61.    {
  62.       this.x -= n;
  63.       this.y -= n;
  64.    }
  65.    function multiply(nFactor)
  66.    {
  67.       var _loc2_ = this.copy();
  68.       _loc2_.x *= nFactor;
  69.       _loc2_.y *= nFactor;
  70.       return _loc2_;
  71.    }
  72.    function divide(n)
  73.    {
  74.       var _loc2_ = this.copy();
  75.       if(n == 0)
  76.       {
  77.          _loc2_.x = 0;
  78.          _loc2_.y = 0;
  79.          return undefined;
  80.       }
  81.       _loc2_.x /= n;
  82.       _loc2_.y /= n;
  83.       return _loc2_;
  84.    }
  85.    function multiplyMe(n)
  86.    {
  87.       this.x *= n;
  88.       this.y *= n;
  89.    }
  90.    function divideMe(n)
  91.    {
  92.       this.x /= n;
  93.       this.y /= n;
  94.    }
  95.    function dot(p)
  96.    {
  97.       return this.x * p.x + this.y * p.y;
  98.    }
  99.    function cross()
  100.    {
  101.       return new smashing.Point(this.y,- this.x);
  102.    }
  103.    function normalize()
  104.    {
  105.       if(!this.x && !this.y)
  106.       {
  107.          return undefined;
  108.       }
  109.       var _loc2_ = this.__get__length();
  110.       return new smashing.Point(this.x / _loc2_,this.y / _loc2_);
  111.    }
  112.    function normalizeMe()
  113.    {
  114.       if(!this.x && !this.y)
  115.       {
  116.          return undefined;
  117.       }
  118.       var _loc2_ = this.__get__length();
  119.       this.x /= _loc2_;
  120.       this.y /= _loc2_;
  121.    }
  122.    function reverse()
  123.    {
  124.       var _loc2_ = new smashing.Point(this.x * -1,this.y * -1);
  125.       return _loc2_;
  126.    }
  127.    function reverseMe()
  128.    {
  129.       this.x *= -1;
  130.       this.y *= -1;
  131.    }
  132.    function rotateMe(nRad)
  133.    {
  134.       var _loc2_ = Math.sin(nRad);
  135.       var _loc3_ = Math.cos(nRad);
  136.       if(_loc2_ > 1 || _loc2_ < -1)
  137.       {
  138.       }
  139.       if(_loc3_ > 1 || _loc3_ < -1)
  140.       {
  141.       }
  142.       this.x = this.x * _loc3_ + this.y * (- _loc2_);
  143.       this.y = this.x * _loc2_ + this.y * _loc3_;
  144.    }
  145.    function rotate(nRad)
  146.    {
  147.       var _loc2_ = Math.sin(nRad);
  148.       var _loc3_ = Math.cos(nRad);
  149.       if(_loc2_ > 1 || _loc2_ < -1)
  150.       {
  151.       }
  152.       if(_loc3_ > 1 || _loc3_ < -1)
  153.       {
  154.       }
  155.       return new smashing.Point(this.x * _loc3_ + this.y * (- _loc2_),this.x * _loc2_ + this.y * _loc3_);
  156.    }
  157.    function rotateSinCos(nSin, nCos)
  158.    {
  159.       this.x = this.x * nCos + this.y * (- nSin);
  160.       this.y = this.x * nSin + this.y * nCos;
  161.    }
  162.    function findCosine(vOther)
  163.    {
  164.       var _loc3_ = this.dot(vOther);
  165.       var _loc4_ = this.__get__length() * vOther.__get__length();
  166.       var _loc2_ = _loc3_ / _loc4_;
  167.       return _loc2_;
  168.    }
  169.    function equals(p)
  170.    {
  171.       if(this.x == p.x && this.y == p.y)
  172.       {
  173.          return true;
  174.       }
  175.       return false;
  176.    }
  177.    function zero()
  178.    {
  179.       this.x = 0;
  180.       this.y = 0;
  181.    }
  182.    function distSqu(p)
  183.    {
  184.       var _loc3_ = p.x - this.x;
  185.       var _loc2_ = p.y - this.y;
  186.       return _loc3_ * _loc3_ + _loc2_ * _loc2_;
  187.    }
  188.    function toString()
  189.    {
  190.       return "Point (" + this.x + "," + this.y + ")";
  191.    }
  192. }
  193.